
import 'package:flutter/material.dart';
import '../../manger/user_manger.dart';
// import '../../services/logger_service.dart';

class MineTopView extends StatefulWidget {
  final VoidCallback onTap;

  const MineTopView({super.key, required this.onTap});

  @override
  State<MineTopView> createState() => MineTopViewState();
}

class MineTopViewState extends State<MineTopView> {
  String _userName = '';

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
          colors: [
            Color(0xFFE1ECFE),
            Color(0xFFE7E5FD),
            Color(0xFFF8F6F7),
          ],
        ),
      ),
      child: Stack(
      children: [
        Positioned(
          top: 50 + MediaQuery.of(context).padding.top,
          left: 15,
          child: GestureDetector(
            // onTap: widget.onTap,
            child: ClipRRect(
              borderRadius: BorderRadius.circular(30),
              child: Image.asset(
                'assets/images/user_logo.png',
                width: 72,
                height: 72,
                fit: BoxFit.cover,
              ),
            ),
          ),
        ),
        Positioned(
          left: 105,
          top: 50 + MediaQuery.of(context).padding.top + 26,
          child: SizedBox(
            width: MediaQuery.of(context).size.width - 140,
            child: Text(
              _userName,
              style: const TextStyle(
                fontSize: 18,
                fontWeight: FontWeight.bold,
                color: Color(0xFF333333),
              ),
            ),
          ),
        ),
      ],
    )
    );
  }


  void updateUserState() {
    setState(() {
      final user = UserInfos.shared.userModel;

      if (UserInfos.shared.token.isNotEmpty && user != null) {
        if (user.email != null && user.email!.email.isNotEmpty) {
          _userName = user.email!.email;
        } else if (user.mobile != null && user.mobile!.mobile.isNotEmpty) {
          _userName = user.mobile!.mobile;
        } else {
          _userName = '';
          //  widget.onTap(); 
        }
      } else {
        _userName = '';
        // widget.onTap(); // 执行跳转
      }
    });

  }
}
